<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="inc/home::header">
</head>

<link type="text/css" th:href="@{/css/content.css}" rel="stylesheet" />
	<body>
		<!--返回-->
		<div class="back"  onclick="location='/index'"><img src="/images/back.png" /></div>
		<div th:include="header :: header"></div>
		<div class="header-title">
			<span>备件管理</span>
		</div>
		<div class="spare-a">
			<div class="spare-al">
				<div style="height:10px"></div>
				<ul>
					<a onclick="loadPage('/Spare/spare')" shiro:hasPermission="sys:spareInventory:spareInventory">
					<li>
						<p>基本信息</p>
					</li>
					</a>
					<a onclick="loadPage('/Spare/storage')" shiro:hasPermission="sys:sparePut:sparePut">
					<li class="active">
						<p>入库</p>
					</li>
					</a>
					<a onclick="loadPage('/Spare/out')" shiro:hasPermission="sys:spareOut:spareOut">
					<li>
						<p>出库</p>
					</li>
					</a>
					<a onclick="loadPage('/Spare/records')" shiro:hasPermission="sys:spareRep:spareRep">
					<li>
						<p>库存</p>
					</li>
					</a>
				</ul>
			</div>
			<div class="spare-ar">
				<div class="spare-ara">
					<div class="spare-ara-a clearfix">
						<div class="spare-ara-al">
							<div class="spare-ara-all"><input type="text" placeholder="请输入名称" name="spareName" id="spareName"/></div>
							<div class="spare-ara-alr" onclick="js_method()"></div>
						</div>
						<div class="spare-ara-ar">
							<a href="#" class="spare-tj" onclick="saveSpHis()" shiro:hasPermission="sys:sparePut:edit">确 定</a>
							<a onclick="loadPage('/Spare/storage-record','N')" class="spare-tj" shiro:hasPermission="sys:sparePut:view">历史记录</a>
						</div>
					</div>
					<div class="srcoll-documentation" id="srcoll-documentation" shiro:hasPermission="sys:sparePut:view">
					<div class="documentation nottake">
						<ul class="lists" id="lists">
							<!-- <a href="#">
							<li>
								<div class="spare-new clearfix">
									<div class="spare-newl">编号/型号：00001000010000100001</div>
									<div class="spare-newl">序列号：10</div>
								</div>
								<div class="spare-new clearfix">
									<div class="spare-newl">名称：油泵</div>
									<div class="spare-newl">数量：<input type="text" class="storage-input" value="100" /></div>
								</div>
								<div class="spare-new clearfix">
									<div class="spare-newl">供应商：29所</div>
									<div class="spare-newl">类型：10</div>
								</div>
								<div class="documentation-check"></div>
							</li>
							</a> -->							
						</ul>
					</div>
				</div>
				</div>
			</div>
			<script type="text/javascript">
			var sparePut = 'hidden';
		</script>
	</div>
	<div shiro:hasPermission="sys:sparePut:sparePut">
		<script type="text/javascript">
		sparePut = '';
		</script>
		</div>
	</body>
	<script th:inline="javascript">
	/*<![CDATA[*/
	 //默认加载   每页显示数据 12              
	$(function() {
		if(sparePut=="hidden"){
			loadPage('/Spare/out')
		}else{
			loadDataPage("/Spare/SpareM/storage", "srcoll-documentation", "lists", 12,"spareName");		
		}		
	});
	function saveSpHis(){
		 if ($('.spare-ara').find('li[class="active"]').length < 0) {
		        $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">请选择一条数据</div></div>', {
		            'title': '提示',
		            'buttons': ['确定']
		        });
		    } else {
		    	 var ids1 = $('.spare-ara').find('li[class="active"]');
				 var val = "";
				 var id = "";
			        for (var i = 0; i < ids1.length; i++) {
			       var nowVal= parseInt($(ids1[i]).find('input[class="storage-input"]').val());
			         if (i < ids1.length - 1&&nowVal>0) {
			                val += $(ids1[i]).find("input").val() + ",";
			                id += $(ids1[i]).attr("id") + ",";
			            }else if (nowVal<=0){
			            	alert("入库数量为零或小于零，请重新输入");			         
			            } else {
			                val += $(ids1[i]).find("input").val();
			                id += $(ids1[i]).attr("id");
			            }
			        }
		        }
	        $.ajax({
			     type: "post",
			     dataType: "json",
			     url: "/Spare/storage/saveOrUpdate?ids="+id+"&val="+val
			 });	
	        window.location.href="/Spare/storage"
	}
	
	
	function js_method() {
		$(".dropload-down").remove();
		$('#lists').html("");
		if(sparePut=="hidden"){
			loadPage('/Spare/out')
		}else{
			loadDataPage("/Spare/SpareM/storage", "srcoll-documentation", "lists", 12,"spareName");		
		}
	}
	 //构建数据列表
	function dataKk(data, me) {
		var result = '';
		var arrLen = data.length;
		if (arrLen > 0) {
			for (var i = 0; i < arrLen; i++) {
				result += '<a href="#">' + '<li id='+data[i].id+'>'
				+ '<div class="spare-new clearfix">'
				+ '<div class="spare-newl">编号/型号：' + data[i].spareCode+ '</div>' 
				+ '<div class="spare-newl">序列号：' + data[i].spareNo+ '</div>'
				+ '</div>'
				+ '<div class="spare-new clearfix">'
				+ '<div class="spare-newl">名称：' + data[i].spareName+ '</div>' 
				+ '<div class="spare-newl">数量：'
				+ '<input type="text" class="storage-input" id="'+data[i].id+'1" onClick="cleanYvalue(this.id)"  value="0">'+ '</input>'
				+ '</div>'
				+ '</div>'
				+ '<div class="spare-new clearfix">'			
				+ '<div class="spare-newl">供应商：' + data[i].spareSupplier+ '</div>'
				+ '<div class="spare-newl">类型：' + data[i].spareType+ '</div>'
				+ '</div>'
				+ '<div class="documentation-check"></div>'
				+ '</li>' + '</a>'
			}
		} else {
			me.lock();
			me.noData();
		}
		return result;
	}
	function cleanYvalue(id){
		document.getElementById(id).value="";		
	 }
	/*]]>*/
</script>
</html>
